<template>
	<view class="content">
		<view class="current">
			<view class="item-cow" v-for="(item,index) in goodsList">
				<view class="t">
					<view class="title">获得积分</view>
					<view class="time">积分时间：{{item.createTime}}</view>
				</view>
				<view class="t-integral" v-if="item.changeType==0">+{{item.changeCount}}</view>
				<view class="t-integral red" v-else>-{{item.changeCount}}</view>
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
    import {_historyIntegral} from '../../common/vmeitime-http/mem.js';
    import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
    import utils from '../../common/utils/util';
	export default {
        components: {
            uniLoadMore
        },
		data() {
			return {
                headerPosition:"fixed",
                headerTop:"0px",
                loadingType: 'more', //加载更多状态
				page:{
                    pageNum:1,
					pageSize:12
				},
                goodsList:[]
			};
		},
		
		onLoad(options){
			// #ifdef H5
			this.headerTop = document.getElementsByTagName('uni-page-head')[0].offsetHeight+'px';
			// #endif
			this.cateId = options.tid;
			
			// ---接口函数---
			// this.loadData();
		},
		onPageScroll(e){
			//兼容iOS端下拉时顶部漂移
			if(e.scrollTop>=0){
				this.headerPosition = "fixed";
			}else{
				this.headerPosition = "absolute";
			}
		},
		//下拉刷新
		onPullDownRefresh(){
			 this.loadData('refresh');
		},
		//加载更多
		onReachBottom(){
			 this.loadData();
		},
		methods: {
			//加载商品 ，带下拉刷新和上滑加载
			async loadData(type,loading) {

				// //没有更多直接返回
				 if(type === 'add'){
				 	if(this.loadingType === 'nomore'){
				 		return;
				 	}
				 	this.loadingType = 'loading';
				 }else{
				 	this.loadingType = 'more'
				 }

				 if(type === 'refresh'){
				 	this.goodsList = [];
				 }


                let tempData = await _historyIntegral(this.para);
                let goodsList = tempData.data.data.list;
                goodsList.forEach((item)=>{
                    item.createTime = utils.formatDate.format(new Date(item.createTime),"yyyy-MM-dd")
				})
                let totalPage = tempData.data.data.totalPage;
                let pNum = this.page.pageNum++;
                this.page.pageNum = totalPage>pNum?pNum+1:totalPage;

				 this.goodsList = this.goodsList.concat(goodsList);

				 //判断是否还有下一页，有是more  没有是nomore(测试数据判断大于20就没有了)
				 this.loadingType  = totalPage > pNum ? 'more' : 'nomore';
				 if(type === 'refresh'){
				 	if(loading == 1){
				 		uni.hideLoading()
				 	}else{
				 		uni.stopPullDownRefresh();
				 	}
				 }
			},
			//详情
			navToDetailPage(item){
				//测试数据没有写id，用title代替
				let id = item.title;
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
			stopPrevent(){}
		},
	}
</script>

<style lang="scss">
	page, .content{
		background: $page-color-base;
	}
	.content{
		/*padding-top: 96upx;*/
	}
	/*当前积分*/
	.current{
		background: #ffffff;
		font-size: 26upx;
		color: $font-color-dark;
		.item-cow{
			display: flex;
			align-items: center;
			padding: 30upx 40upx;
			clear: both;
			border-bottom: 2upx solid #f6f6f6;
			.t{
				flex: 1;
				.time{
					font-size: 20upx;
					color: #989898;
					margin-top: 10upx;
				}
			}
			.t-integral{
				display: inline-block;
				color: $uni-color-primary;
				font-size: 36upx;
				&.red{
					color: $uni-color-error;
				}
			}
		}
	}
</style>
